home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / TwinOpus2 / REXX / DOpus / ReadDir.rexx < prev    next >
OS/2 REXX Batch file  |  1994-10-13  |  3KB  |  130 lines

  1. /*
  2.  *
  3.  * Get the contents of a directory from TwinExpres from DOpus.
  4.  *
  5.  * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
  6.  *
  7.  * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
  8.  * use GuiArc in stead of DOpus and a script, to deal with archives)
  9.  *
  10.  */
  11.  
  12.  
  13. DOpusPort   = 'DOPUS.1'
  14. HandlerPort = 'TWIN.1'
  15.  
  16.  
  17. userdata     = '  0'      /* default      */
  18. fgpen        = '  1'      /* palette 1    */
  19. dirpen       = '  3'      /* for directories */
  20. bgpen        = '  0'      /* palette 2    */
  21. selectable   = ' 1'       /* can select   */
  22. unselectable = ' 0'       /* can't select */
  23. show         = ' 0'       /* update win   */
  24. before       = ' -1'      /* add to end   */
  25.  
  26. if ~show(l,"rexxsupport.library") then        
  27.     call addlib("rexxsupport.library",0,-30,0)
  28. if showlist('Ports', DOpusPort) = 0 then do
  29.    say 'Directory Opus Arexx port not found. Aborting.'
  30.    call CleanUp
  31. end
  32.  
  33. address 'DOPUS.1'
  34. options results
  35.  
  36.  
  37. /* Get some information from DOpus */
  38. parse arg FilePath
  39. if FilePath="" then do
  40.    TopText "You have to specify a directory."
  41.    exit
  42. end
  43. Status 3
  44. CurrentWindow = Result
  45.  
  46. /* setup DOpus window and tell user what's happening */
  47. ClearWin CurrentWindow
  48. SetWinTitle FilePath
  49. Busy on
  50. TopText "Getting directory of CD, please wait..."
  51.  
  52. /* Address the list commando and a help to 'flush' the queue buffer
  53.  * never use a queue with a bigger buffer than the default buffer.
  54.  * The queue-handler doesn't flush automaticly!
  55.  */
  56. address command 'echo >PPipe: dir' FilePath
  57. address command 'echo >PPipe: help'
  58.  
  59. /* parse the result from pipe: */
  60. TopText "Parsing File(s). Please Wait..."
  61. call ParseDir
  62. 'DisplayDir -1'
  63.  
  64. /* if handler is running, attach a custom handler to the window */
  65. if show('p', HandlerPort) then 
  66.    'AddCustHandler '||HandlerPort||' -1'
  67.  
  68. Busy off
  69. call CleanUp
  70. exit
  71.  
  72. /*---------------------------------------------------------------------------*/
  73.  
  74. ParseDir:
  75.  
  76.    if open(PipeList, "QUEUE:Twin", 'R') then do
  77.  
  78.       /* skip the header and the 'help-flush' from the last call... */
  79.       junk = ''
  80.       do while left(junk, 10, '') ~= "Listing of"
  81.          junk = readln(PipeList)
  82.       end
  83.       junk = readln(PipeList)
  84.  
  85.       /* read files and dirs */
  86.       line = readln(PipeList)
  87.       do while length(line) ~= 0
  88. /*      do while left(line,4) ~= "TWIN" */
  89.          File = Quote(line)
  90.          if SubStr(line,26,9) = 'Directory' then
  91.             Entry = File || userdata || dirpen || bgpen || selectable || show || before
  92.          else
  93.             Entry = File || userdata || fgpen || bgpen || selectable || show || before 
  94.          AddCustEntry Entry
  95.          line = readln(PipeList)
  96.       end
  97.  
  98.       /* add invisible entry giving us the path and for recognition */
  99.       File = Quote('*'||FilePath)
  100.       Entry = File || userdata || bgpen || bgpen || unselectable || show || before 
  101.       AddCustEntry Entry
  102.  
  103.       close(PipeList)
  104.    end
  105.  
  106.    else do
  107.       TopText "Can't open pipe:"
  108.       call CleanUp
  109.    end
  110.  
  111. return
  112.  
  113. /*---------------------------------------------------------------------------*/
  114.  
  115. CleanUp:
  116.  
  117.    TopText "Ready"
  118.    Busy off
  119.    exit
  120.  
  121. return
  122.  
  123. /*---------------------------------------------------------------------------*/
  124.  
  125. Quote: procedure /* add quotes to string */
  126.  
  127.    parse arg string
  128.  
  129. return '"'||string||'"'
  130.